import Vue from "vue";
import VueRouter from "vue-router";
// 路由
import Layout from "@/views/layout"; //主页面
import Login from "@/views/login"; //登录页
import Dashboard from "@/views/dashboard";
// 基础数据管理二级路由
import OrganizationManage from "@/views/branches/organization-manage";
import InstitutionsJobsArea from "@/views/branches/institutions-jobs-area";
import FreightManage from "@/views/branches/freight-manage";
// 车辆管理
import CarModels from "@/views/transit/car-models";
import Vehicle from "@/views/transit/vehicle";
import CarRegister from "@/views/transit/car-register";
// 车辆管理/跳转
import vehicleDetail from "@/views/transit/vehicle/componets/vehicle-detail";
// 员工管理
import OperationalRange from "@/views/staff/operational-range";
import Driver from "@/views/staff/driver";
import WorkArrangeManage from "@/views/staff/workArrange-manage";
// 业务管理
import OrderManage from "@/views/business/order-manage";
import Waybill from "@/views/business/waybill";
// 调度管理
import TransportTask from "@/views/transport/transport-task";
import LineManage from "@/views/transport/line-manage";
import PickUptask from "@/views/transport/pickUptask";
import DispatchTask from "@/views/transport/dispatchTask";
import LookOver from "@/views/transit/car-register/lookOver";
import MapContent from "@/views/staff/operational-range/mapContent";
import DriverDetail from "@/views/staff/driver/driver-detail";
import WorkArrangeSetting from "@/views/staff/workArrange-manage/workArrange-setting";

import store from "@/store";
Vue.use(VueRouter);

const routes = [
  { path: "/login", component: Login },
  {
    path: "/",
    component: Layout,
    redirect: "/dashboard",
    children: [
      { path: "dashboard", component: Dashboard },
      { path: "organization-manage", component: OrganizationManage },
      { path: "institutions-jobs-area", component: InstitutionsJobsArea },
      { path: "freight-manage", component: FreightManage },
      { path: "car-models", component: CarModels },
      { path: "vehicle", component: Vehicle },
      { path: "car-register", component: CarRegister },
      { path: "operational-range", component: OperationalRange },
      { path: "driver", component: Driver },
      { path: "workArrange-manage", component: WorkArrangeManage },
      { path: "order-manage", component: OrderManage },
      { path: "waybill", component: Waybill },
      { path: "transport-task", component: TransportTask },
      { path: "line-manage", component: LineManage },
      { path: "pickUptask", component: PickUptask },
      { path: "dispatchTask", component: DispatchTask },
      { path: "vehicle-detail", component: vehicleDetail },
      { path: "lookOver", component: LookOver },
      { path: "mapContent", component: MapContent },
      { path: "driver-detail", component: DriverDetail },
      { path: "workArrange-setting", component: WorkArrangeSetting },
    ],
  },
];

const router = new VueRouter({
  routes,
});

// 路由守卫
router.beforeEach((to, from, next) => {
  // console.log(store.state.user);
  const { token } = store.state.user;
  if (to.path !== "/login" && !token) return next("/login");
  next();
});

export default router;
